package Demo;

import java.util.concurrent.atomic.AtomicInteger;

//通过Leamda表达式创建多线程
public class LeamdaThread {
    public static void main(String[] args) {
        //安全线程
        AtomicInteger atomicInteger =new AtomicInteger(0);
        Thread t1=new Thread(()->{
            for (int i = 0; i < 10; i++) {
               //先自增，后取值
               int j=atomicInteger.incrementAndGet();
                System.out.println("j_T1="+j);
               //自增++
            }
        });
        t1.start();

        Thread t2=new Thread(()->{
            for (int i = 0; i < 10; i++) {
               //先自增，后取值
               int j=atomicInteger.decrementAndGet();
               System.out.println("j_T2="+j);
               //自减
            }
        });

        t2.start();


    }
}
